﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;

using System.Diagnostics;

namespace LowLevelGraphics.ImageFormats.SVG.Shapes
{
    /// <summary>
    /// 
    /// </summary>
    [DebuggerDisplay("X: {X}, Y: {Y}, Width: {m_fWidth}, Height: {m_fHeight}, Rx: {m_fRx}, Ry: {m_fRy}")]
    public class Rectangle : Shape
    {
        protected float m_fWidth = -1;
        protected float m_fHeight = -1;
        protected float m_fRx = -1;
        protected float m_fRy = -1;

        /// <summary>
        /// Initializes a new instance of the <see cref="Rectangle"/> class.
        /// </summary>
        public Rectangle()        
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Rectangle"/> class.
        /// </summary>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="rx">The rx.</param>
        /// <param name="ry">The ry.</param>
        public Rectangle(float x, float y, float width, float height, float rx, float ry)
        {
            this.X = x;
            this.Y = y;
            m_fWidth = width;
            m_fHeight = height;
            m_fRx = rx;
            m_fRy = ry;
        }

        /// <summary>
        /// Gets or sets the width.
        /// </summary>
        /// <value>The width.</value>
        public float Width
        {
            get { return m_fWidth; }
            set { m_fWidth = value; }
        }

        /// <summary>
        /// Gets or sets the height.
        /// </summary>
        /// <value>The height.</value>
        public float Height
        {
            get { return m_fHeight; }
            set { m_fHeight = value; }
        }

        /// <summary>
        /// Gets or sets the rx.
        /// </summary>
        /// <value>The rx.</value>
        public float Rx
        {
            get { return m_fRx; }
            set { m_fRx = value; }
        }

        /// <summary>
        /// Gets or sets the ry.
        /// </summary>
        /// <value>The ry.</value>
        public float Ry
        {
            get { return m_fRy; }
            set { m_fRy = value; }
        }

        /// <summary>
        /// Draws the specified g.
        /// </summary>
        /// <param name="g">The g.</param>
        public override void Draw(Graphics g)
        {
            if (m_fRx > 1 || m_fRy > 1)
            {
                Brush brush = new SolidBrush(Style.FillColor);
                Pen pen = new Pen(brush, Style.StrokeWidth);
                RoundedRectangleRegion rect = new RoundedRectangleRegion();
                Region region = rect.GetRoundedRect(new RectangleF(X, Y, m_fWidth, m_fHeight), (int)m_fRx);
                g.FillRegion(brush, region);
                brush.Dispose();
                pen.Dispose();
            }
            else
            {
                Brush brushFill = new SolidBrush(Style.FillColor);
                Pen penStroke = new Pen(new SolidBrush(Style.StrokeColor), Style.StrokeWidth);
                g.FillRectangle(brushFill,X, Y, m_fWidth, m_fHeight);
                g.DrawRectangle(penStroke, X, Y, m_fWidth, m_fHeight);
                brushFill.Dispose();
                penStroke.Dispose();
            }
        }
    }
}
